package com.kaifamiao.schedule;

public class JoinTest1 {

    public static void main(String[] args) throws InterruptedException {
        final Thread x = Thread.currentThread();
        System.out.printf("%s 线程\n", x.getName());

        Thread t = new Thread("苏哥拉弟"){
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                for (int i = 1; i < 6; i++) {
                    System.out.printf("%s 线程 - %d .\n", name , i);
                }
            }
        };

        t.start();

        for (int i = 1; i < 6; i++) {
            System.out.printf("%s 线程 - %d .\n", x.getName() , i);
            if( i == 2 ) {
                // 等待另一个线程执行结束
                t.join(); // 线程 x 等待 线程 t 执行结束后再恢复执行
            }
        }
    }

}
